﻿using OnlineAuction.Business;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace OnlineAuction.Admin
{
    public partial class Statistic : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.Cookies["UserInfo"] == null
                || Request.Cookies["UserInfo"]["Role"].ToString().CompareTo("Admin") != 0)
            {
                Response.Redirect("../Home.aspx");
            }
            else if (!Page.IsPostBack)
            {
                //Get all category
                CategoryBO categoryBO = new CategoryBO();
                ddlCategory.DataTextField = "CategoryName";
                ddlCategory.DataValueField = "CategoryID";
                ddlCategory.DataSource = categoryBO.GetCategory();
                ddlCategory.DataBind();
                //Get all category
                AuctionStateBO auctionStateBO = new AuctionStateBO();
                ddlStatus.DataTextField = "AuctionStateName";
                ddlStatus.DataValueField = "AuctionStateID";
                ddlStatus.DataSource = auctionStateBO.GetAuctionState();
                ddlStatus.DataBind();
            }
            LoadStatistic();
        }

        private void LoadStatistic()
        {
            AuctionBO bo = new AuctionBO();
            grvStatistic.DataSource = bo.Statistic(
                    ddlCategory.SelectedValue, txtTimeFrom.Text,
                    txtTimeTo.Text, txtPriceFrom.Text, txtPriceTo.Text,
                    ddlStatus.SelectedValue);
            grvStatistic.DataBind();
        }

        protected void btnStatistic_Click(object sender, EventArgs e)
        {
            LoadStatistic();
        }
        protected void UpdateTimer_Tick(object sender, EventArgs e)
        {
            LoadStatistic();
        }

    }
}